package dk.mitaffald.main;


import dk.tankegang.mitaffald.R;
import dk.mitaffald.main.MyLocation.LocationResult;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.location.Location;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Looper;
import android.provider.Settings;
import android.view.MotionEvent;
import android.widget.Toast;

public class Starter extends Activity{
	
	private Thread mSplashThread;  
    LocationManager lm;

    private static final String TAG = "Debug of Ohad's Project"; // 
	
	public void onCreate(Bundle paramBundle)
	    {
	        super.onCreate(paramBundle);
	        setContentView(R.layout.starter);
	       		    
	        
	        LocationResult locationResult = new LocationResult(){
	            @Override
	            public void gotLocation(Location location)
	            {
	      
	                SQLiteDatabase db = openOrCreateDatabase("mydb.db", Context.MODE_PRIVATE, null);
	                db.execSQL("CREATE TABLE IF NOT EXISTS gps_kordinater (ID INTEGER PRIMARY KEY AUTOINCREMENT, Latitude REAL, Longitude REAL);");

	                ContentValues gps_values = new ContentValues();
	                

	                gps_values.put("Latitude", location.getLatitude());
	                gps_values.put("Longitude", location.getLongitude());
	   

	                 try {
	                     db.beginTransaction();
	                     db.insert("gps_kordinater", null, gps_values);
	                     db.setTransactionSuccessful();
	                 } finally {
	                     db.endTransaction();
	                 }
	         }
	            
	            
	           };
	        MyLocation myLocation = new MyLocation();
            
	        myLocation.getLocation(this, locationResult);
	        
	        
	        
	        
	       final Starter sPlashScreen = this; 
	           
	        mSplashThread =  new Thread(){
    @Override
    public void run(){
        try {
        	synchronized(this){
                wait(5000);
                
            	
                
            }
        }
        	catch(InterruptedException ex){                    
        }

        Looper.prepare();
        finish();
        
        Intent intent = new Intent();
        intent.setClass(sPlashScreen,DashboardMain.class);
        startActivity(intent);
        //finish();                   
    }
};

mSplashThread.start();        
}

// Processes splash screen touch events

@Override
 	public boolean onTouchEvent(MotionEvent evt) {
	
	if(evt.getAction() == MotionEvent.ACTION_DOWN)
	{
		synchronized(mSplashThread)
		{
        mSplashThread.notifyAll();
		}
	}
	return true;
  }



}

